package com.face.JPanel;


import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JTextArea;
import javax.swing.Box;
import javax.swing.border.EmptyBorder;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JEditorPane;
import java.awt.Component;
import javax.swing.JLabel;

public class CheckProblemPanel extends JPanel {
	private JTextField []answertext;
	private JTextArea problem;
	private Box answers;
	private JTextField txtA;
	private JLabel tno;
	private Box horizontalBox;
	/**
	 * Create the panel.
	 */
	
	public String getProblem()
	{
		return problem.getText();
	}
	
	public String[] getAnswers()
	{
		String []temp=new String[answertext.length];
		for(int i=0;i<answertext.length;i++)
			temp[i]=answertext[i].getText();
		return temp;
	}
	
	public void setProblem(String problem)
	{
		this.problem.setText(problem);
	}
	public void setAnswers(String []an)
	{
		Font font=new Font("Monospaced", Font.PLAIN, 18);
		answertext=new JTextField[an.length];
		char A='A';
		for(int i=0;i<an.length-1;i++)
		{
			answertext[i] = new JTextField((char)(A+i)+"."+an[i]);
			answertext[i].setFont(font);
			answers.add(answertext[i]);
			Component verticalStrut = Box.createVerticalStrut(20);
			answers.add(verticalStrut);
		}
		answertext[an.length-1] = new JTextField((char)(A+an.length-1)+"."+an[an.length-1]);
		answertext[an.length-1].setFont(font);
		answers.add(answertext[an.length-1]);
	}
	
	public String getAnswer()
	{
		return txtA.getText();
	}
	public void setAnswer(String an)
	{
		txtA.setText(an);
	}
	public void setNO(int n)
	{
		tno.setText(n+".");
	}
	public CheckProblemPanel() {
		setBorder(new EmptyBorder(5, 5, 5, 5));
		setLayout(new BorderLayout(0, 0));
		
		horizontalBox = Box.createHorizontalBox();
		add(horizontalBox, BorderLayout.NORTH);
		
		tno = new JLabel();
		tno.setAlignmentY(Component.TOP_ALIGNMENT);
		tno.setAlignmentX(Component.CENTER_ALIGNMENT);
		horizontalBox.add(tno);
		
		problem = new JTextArea();
		problem.setAlignmentY(Component.TOP_ALIGNMENT);
		horizontalBox.add(problem);
		problem.setFont(new Font("Monospaced", Font.PLAIN, 18));
		problem.setRows(3);
		
		answers = Box.createVerticalBox();
		answers.setBorder(new EmptyBorder(10, 10, 10, 10));
		add(answers, BorderLayout.CENTER);
		
		JPanel panel = new JPanel();
		add(panel, BorderLayout.SOUTH);
		
		JLabel lblNewLabel = new JLabel("\u7B54\u6848:");
		panel.add(lblNewLabel);
		
		txtA = new JTextField();
		
		panel.add(txtA);
		txtA.setColumns(10);
		

	}

}
